<template>
  <div>
    <h3 align="center">部门信息列表</h3>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话"
        width="180">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="200">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="出生日期"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
      </el-table>
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        align="right">
      </el-pagination>
  </div>
</template>

<script>
import Vue from "vue";
export default {
  name: "department",
  data() {
    return {
      tableData: [],
      currentPage : 1,
      pageSize : 10,
      total : 0
    }
  },
 mounted() { // 钩子函数，用来发送axios请求
    this.list()
  },
  methods : {
    handleCurrentChange(val) {
      this.currentPage = val
      this.list();
    },
    handleSizeChange(val) {
      this.pageSize = val
    },
    list() {
      this.$http.get("https://www.fastmock.site/mock/e0d8ef3045526d891a439d317f98638a/department/department/list",{"currentPage" : this.currentPage, "pageSize" : this.pageSize})
        .then(result=>{
          // 访问接口成功，且返回数据走此
          this.tableData = result.data.data
          this.total = result.data.totals
        })

      .catch(error=>{
        // 访问接口出现异常高走此
        alert("系统繁忙，请稍后重试")
        console.log(error)
      })
    }
  }
}
</script>

<style scoped>

</style>
